package com.khadi.testcase.view.editor;

import java.awt.Component;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.AbstractCellEditor;
import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.table.TableCellEditor;

import com.khadi.testcase.util.UIHelper;

public class SortLabelEditor extends AbstractCellEditor implements
		TableCellEditor {

	/**
	 * 
	 */
	private static final long serialVersionUID = -5085578448725247452L;

	private JLabel lbUpArrow;
	private JLabel lbDownArrow;
	private JLabel lbSort;

	private int currentValue = 0;
	private static final int FIRST_ROW = 1;

	private MouseAdapter mouseListener;

	public SortLabelEditor() {
		this.lbUpArrow = new JLabel(UIHelper
				.getImageIcon(UIHelper.IMG_ARROW_UP));
		this.lbDownArrow = new JLabel(UIHelper
				.getImageIcon(UIHelper.IMG_ARROW_DOWN));
		this.lbSort = new JLabel(UIHelper.getImageIcon(UIHelper.ICON_SORT));

		this.lbUpArrow.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {

			}
		});
	}

	@Override
	public Object getCellEditorValue() {

		return null;
	}

	public MouseAdapter getMouseListener() {
		if (mouseListener == null) {
			mouseListener = new MouseAdapter() {
				@Override
				public void mouseClicked(MouseEvent e) {
					if (e.getComponent() == (SortLabelEditor.this.lbDownArrow)) {
						
					}
				}
			};
		}
		return mouseListener;
	}

	@Override
	public Component getTableCellEditorComponent(JTable table, Object value,
			boolean isSelected, int row, int column) {
		int ROW_NUMBER = row + 1;
		int rowCount = table.getModel().getRowCount();
		this.currentValue = (Integer) value;
		if (rowCount == 1) {
			return new JLabel("kk");
		} else if (rowCount == ROW_NUMBER) {
			return lbUpArrow;
		} else if (ROW_NUMBER == FIRST_ROW) {
			return lbDownArrow;
		} else if (rowCount != ROW_NUMBER) {
			return lbSort;
		}
		return null;
	}
}
